import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(new BottomAppBarPlugin());
}

/*
 * 底部工具栏组件 <br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
class BottomAppBarPlugin extends StatefulWidget {
  State<StatefulWidget> createState() {
    return new BottomAppBarPluginState();
  }
}

/*
 * 页面功能 <br/>
 */
class BottomAppBarPluginState extends State<StatefulWidget> {
  final key_btn_right = GlobalKey();

  void initState() {
    super.initState();
  }

  Widget buildOld(BuildContext context) {
    AppBar appBar = AppBar(
      leading: new IconButton(
        icon: new Icon(Icons.arrow_back),
        onPressed: () {},
      ),
      title: new Text('FlutterDesign'),
      centerTitle: true,
      actions: <Widget>[
        new Container(width: 0, height: 0),
        new Container(width: 0, height: 0),
      ],
      backgroundColor: Colors.blue,
    );

    return MaterialApp(
      home: new Scaffold(
        appBar: appBar,
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
        ),
        body: new Builder(builder: (BuildContext context) {
          return Text('登录');
        }),
        backgroundColor: Colors.white,
        bottomNavigationBar: BottomAppBar(
          color: Colors.red,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              IconButton(
                icon: Icon(
                  Icons.home,
                  color: Colors.white,
                ),
                color: Colors.white,
                onPressed: () {
                  setState(() {});
                },
              ),
              IconButton(
                icon: Icon(Icons.access_alarms, color: Colors.white),
                color: Colors.white,
                onPressed: () {
                  setState(() {});
                },
              ),
            ],
          ),
        ),
      ),
    );
  }


  Widget build(BuildContext context) {
    AppBar appBar = AppBar(
      leading: new IconButton(
        icon: new Icon(Icons.arrow_back),
        onPressed: () {},
      ),
      title: new Text('FlutterDesign'),
      centerTitle: true,
      actions: <Widget>[
        new Container(width: 0, height: 0),
        new Container(width: 0, height: 0),
      ],
      backgroundColor: Colors.blue,
    );

    return MaterialApp(
      home: new Scaffold(
        appBar: appBar,
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
        ),
        body: new Builder(builder: (BuildContext context) {
          return Text('登录');
        }),
        backgroundColor: Colors.white,
        bottomNavigationBar: createBottomNavigationBar(),
      ),
    );
  }


  /*
   * 创建底部导航栏的函数
   */
  Widget createBottomNavigationBar()
  {
    Widget navigationBar = new CupertinoTabBar(
        currentIndex: 0,
        onTap: (index)
        {
          setState(()
          {
          });
        },
        items: createBottomNavigationBarItem());
    return navigationBar;
  }

  /*
   * 创建底部导航栏的BarItem函数
   */
  List<BottomNavigationBarItem> createBottomNavigationBarItem()
  {
    List<BottomNavigationBarItem> mBottomNavigationBarList= new List();
    for (int i = 0; i < 2; i++)
    {
      mBottomNavigationBarList.add(new BottomNavigationBarItem(
          icon: new Icon(Icons.access_alarms, color: Colors.red, size: 20.0),
          title: new Text(
           '测试${i}',
            style: TextStyle(color:Colors.green),
          )));
    }
    return mBottomNavigationBarList;
  }

}
